package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import stuff.CloseAction;

public class GUIDialog  extends CustomJPanel{
	
	private static final long serialVersionUID = 1L;
	protected JFrame parent;
	protected JPanel titlePanel, contentPanel;
	protected Font font;
	protected JLabel titlebar;
	protected JButton exitButton;
	
	public GUIDialog(JFrame param, int cornerIndex, Font font) {
		super(param, cornerIndex);
		this.font = font;
		//setPreferredSize(new Dimension(800, 600));
		setLayout(new BorderLayout());
		
		titlePanel = new JPanel(new BorderLayout());
		titlePanel.setOpaque(false);
		titlebar = new JLabel("ThiGPLX Server");
		titlebar.setForeground(new Color(255, 255, 255, 200));
		titlePanel.setBorder(new EmptyBorder(0, 10, 0, 3));
		JPanel topRight = new JPanel(new FlowLayout(FlowLayout.RIGHT));
		exitButton = new CustomJButton("", 20, 20, 
				CustomJButton.RED, CustomJButton.LIGHTER, Color.DARK_GRAY, 0, true, false);
		exitButton.setAction(new CloseAction());
		topRight.add(exitButton);
		topRight.setOpaque(false);
		titlePanel.add(titlebar,BorderLayout.CENTER);
		titlePanel.add(topRight,BorderLayout.EAST);
		
		contentPanel = new JPanel(new BorderLayout(20, 20));
		contentPanel.setOpaque(false);
		
		add(titlePanel,BorderLayout.NORTH);
		add(contentPanel,BorderLayout.CENTER);
	}
	
	public void setTitle(String param){
		this.titlebar.setText(param);
	}
	
	class DisposeAction extends AbstractAction {

		private static final long serialVersionUID = 1L;
		private JFrame param;
		
		public DisposeAction(JFrame paramz) {
			this.param = paramz;
		}
		
		@Override
		public void actionPerformed(ActionEvent e) {
			param.dispose();
		}
	}
}
